package com.ld.caodan.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TabHost;

/**
 * 创建TabActivity
 * 
 * @author LD
 * 
 *         下午03:34:33 2012-5-22
 */
public class TabHostActivity extends TabActivity implements
		OnCheckedChangeListener {
	/** Called when the activity is first created. */

	private Intent shouye;
	private Intent aiqing;
	private Intent qian;
	private Intent gongzuo;
	private Intent jiating;
	private Intent xuexiao;
	private Intent xing;
	private Intent xiaohai;
	private Intent jiankang;
	private Intent luanqibazao;
	private TabHost mTabHost;

	private static final String ONE = "1";
	private static final String TWO = "2";
	private static final String THREE = "3";
	private static final String FOUR = "4";
	private static final String FIVE = "5";
	private static final String SIX = "6";
	private static final String SEVEN = "7";
	private static final String EIGHT = "8";
	private static final String NINE = "9";
	private static final String TEN = "10";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tabhost);
		this.shouye = new Intent(this, CD_ShouYe_Activity.class);
		this.aiqing = new Intent(this, CD_AiQing_Activity.class);
		this.qian = new Intent(this, CD_Qian_Activity.class);
		this.gongzuo = new Intent(this, CD_GongZuo_Activity.class);
		this.jiating = new Intent(this, CD_JiaTing_Activity.class);
		this.xuexiao = new Intent(this, CD_XueXiao_Activity.class);
		this.xing = new Intent(this, CD_Xing_Activity.class);
		this.xiaohai = new Intent(this, CD_XiaoHai_Activity.class);
		this.jiankang = new Intent(this, CD_JianKang_Activity.class);
		this.luanqibazao = new Intent(this, CD_LuanQiBaZao_Activity.class);
		// 给Radiobutton添加点击事件
		addOnCheckedChangeListener();

		this.mTabHost = getTabHost();

		mTabHost.addTab(buildTabSpec(ONE, R.string.shouye, this.shouye));

		mTabHost.addTab(buildTabSpec(TWO, R.string.aiqing, this.aiqing));

		mTabHost.addTab(buildTabSpec(THREE, R.string.qian, this.qian));

		mTabHost.addTab(buildTabSpec(FOUR, R.string.gongzuo, this.gongzuo));

		mTabHost.addTab(buildTabSpec(FIVE, R.string.jiating, this.jiating));

		mTabHost.addTab(buildTabSpec(SIX, R.string.xuexiao, this.xuexiao));
		
		mTabHost.addTab(buildTabSpec(SEVEN, R.string.xing, this.xing));

		mTabHost.addTab(buildTabSpec(EIGHT, R.string.xiaohai, this.xiaohai));

		mTabHost.addTab(buildTabSpec(NINE, R.string.jiankang, this.jiankang));

		mTabHost.addTab(buildTabSpec(TEN, R.string.luanqibazao,
				this.luanqibazao));
	}

	private void addOnCheckedChangeListener() {
		int menuCount = 10;
		for (int i = 0; i < menuCount; i++) {
			RadioButton button = ((RadioButton) findViewById(R.id.radio_button0
					+ i));
			if (button != null)
				button.setOnCheckedChangeListener(this);
		}
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			switch (buttonView.getId()) {
			case R.id.radio_button0:
				this.mTabHost.setCurrentTabByTag(ONE);
				break;
			case R.id.radio_button1:
				this.mTabHost.setCurrentTabByTag(TWO);
				break;
			case R.id.radio_button2:
				this.mTabHost.setCurrentTabByTag(THREE);
				break;
			case R.id.radio_button3:
				this.mTabHost.setCurrentTabByTag(FOUR);
				break;
			case R.id.radio_button4:
				this.mTabHost.setCurrentTabByTag(FIVE);
				break;
			case R.id.radio_button5:
				this.mTabHost.setCurrentTabByTag(SIX);
				break;
			case R.id.radio_button6:
				this.mTabHost.setCurrentTabByTag(SEVEN);
				break;
			case R.id.radio_button7:
				this.mTabHost.setCurrentTabByTag(EIGHT);
				break;
			case R.id.radio_button8:
				this.mTabHost.setCurrentTabByTag(NINE);
				break;
			case R.id.radio_button9:
				this.mTabHost.setCurrentTabByTag(TEN);
				break;
			}
		}
	}

	private TabHost.TabSpec buildTabSpec(String tag, int resLabel,
			final Intent intent) {
		return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel))
				.setContent(intent);
	}

}